﻿//	Copyright (c) 2012 Jonathan Loe
//
//	MIT license (http://en.wikipedia.org/wiki/MIT_License)
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights 
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
//	of the Software, and to permit persons to whom the Software is furnished to do so, 
//	subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in all 
//	copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
//	INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
//	PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
//	FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//	ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;
using System.Transactions;

using Ordinaire;
using Ordinaire.Security;
using Ordinaire.Taxonomy;
using Ordinaire.Taxonomy.Data;
using Ordinaire.Business.FoodBeverage.Taxonomy.Data;

namespace Ordinaire.Business.FoodBeverage.Sales
{
    /// <summary>
    /// Represents a menu.
    /// </summary>
    public class Menu : Ordinaire.Business.Catalogue<int, FbGood, Data.GoodData>
    {
        /// <summary>
        /// Adds new item into menu.
        /// </summary>
        /// <param name="item">sale item to add</param>
        /// <param name="who">user who wish to add this item</param>
        /// <returns>true if item is successful addd into the menu, else false</returns>
        //public bool Add(SaleItem item, User who)
        //{
        //    if (item == null)
        //    {
        //        throw new ArgumentNullException("item");
        //    }

        //    if (who == null)
        //    {
        //        throw new ArgumentNullException("who");
        //    }

        //    try
        //    {
        //        using (TransactionScope transaction = new TransactionScope())
        //        {
        //            FbContext context = (FbContext)Context;

        //            // Add new sale item
        //            Data.SaleItem data = new Data.SaleItem();
        //            data.Name      = item.Name;
        //            if (item is Food)
        //            {
        //                data.Description = ((Food)item).Description;
        //            }
        //            data.Type      = item.GetType().Name;
        //            data.Qty       = item.Quantity;
        //            data.Unit      = item.Unit;
        //            data.Price     = item.Price;
        //            data.Discount  = item.Discount;
        //            data.Tax       = item.Tax;
        //            data.CreatedBy = who.Username;
        //            context.SaleItems.InsertOnSubmit(data);
        //            context.SubmitChanges();

        //            // Tag it accordingly
        //            Organiser<int, SaleItemTag> organiser = new Organiser<int, SaleItemTag>();
        //            string tagName = item.GetType().Name;
        //            organiser.Tag(data, new string[] { tagName }, who);
        //            transaction.Complete();
        //            return true;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ExceptionFactory.Create<FbException>(ex, ExceptionMessage.Failure, "add new sale item");
        //    }
        //}
    }
}
